package com.example.zbh.dsliao.application;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.baidu.mapapi.SDKInitializer;
import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMChatOptions;
import com.easemob.chat.EMMessage;
import com.easemob.chat.OnMessageNotifyListener;
import com.example.zbh.dsliao.DlHelper;
import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.db.entity.DaoMaster;
import com.example.zbh.dsliao.db.entity.DaoSession;
import com.parse.Parse;

import java.util.LinkedList;
import java.util.List;


/**
 * Created by zbh on 15/11/16.
 */
public class App extends Application {
    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        this.context = this;

        //百度地图初始化工作
        SDKInitializer.initialize(this);

        //初始化parse
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "oJXVuK4lOoGbMdHOqSrZayLcsLF9cVRskmYVis7X", "abpLXOYuC6LyLQmzkBgRKYHZyfsAsgVzBUJ9VXc7");


        EMChat.getInstance().init(this);
        EMChat.getInstance().setDebugMode(true);
        DlHelper.getDlHelper().init(this);
        // 获取到EMChatOptions对象
        EMChatOptions options = EMChatManager.getInstance().getChatOptions();
        // 默认添加好友时，是不需要验证的，改成需要验证
        options.setAcceptInvitationAlways(false);
        // 默认环信是不维护好友关系列表的，如果app依赖环信的好友关系，把这个属性设置为true
        options.setUseRoster(true);
        // 设置后台接受新消息时是否通过通知栏提示
        options.setShowNotificationInBackgroud(true);

        //在后台时 来信消息的通知 (暂时youbu好使)
        options.setNotifyText(new OnMessageNotifyListener() {
            @Override
            public String onNewMessageNotify(EMMessage emMessage) {

                return emMessage.getFrom() + "给您发送了一条消息";
            }

            @Override
            public String onLatestMessageNotify(EMMessage emMessage, int i, int i1) {
                return i + "" + i1 + "shenm";
            }

            @Override
            public String onSetNotificationTitle(EMMessage emMessage) {
                return "屌聊小助手提醒您..";
            }

            @Override
            public int onSetSmallIcon(EMMessage emMessage) {

                return R.drawable.dl_default_avatar;
            }
        });


//        CrashHandler crashHandler = CrashHandler.getInstance();
//        crashHandler.init(getApplicationContext());
    }


    public static Context getContext(){
        return context;
    }


}
